#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <net-snmp/agent/net-snmp-agent-includes.h>
#include <stdarg.h>
#include <stdio.h>
#include "snmprdbms.h"
#include "snmprdbms_config.h"
#include "snmprdbms_ds.h"
#include "snmprdbms_odbc.h"

//debug messages
void debug(const char *msg,...) {
  va_list argp;
  char f_msg[DEBUG_MSG_MAX_LEN];

  va_start(argp, msg);
  vsprintf(f_msg, msg, argp);
  DEBUGMSGTL((DEBUG_TOKEN, f_msg));
  va_end(argp);
}

//oid to string converter for debug output
char *oid2str(const oid *oid_obj, size_t oid_obj_size) {
  char *str = malloc(MAX_OID_LEN*2);
  if (snprint_objid(str, MAX_OID_LEN*2, oid_obj, oid_obj_size) > 0)
    return str;
  else
    return SNMPRDBMS_ERROR;
}

void
init_snmprdbms(void) {

  debug("Initializing the ODBC module...\n");

  if ( config_init_datastore() == NULL ) {
    debug("Error allocate memory in datastore\n");
    return;
  }

  //netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_APPTYPE, "snmpodbc");

  snmpd_register_config_handler(CONF_DEFINE,
                                parse_config,
                                free_config,
                                "Type definition");
  snmpd_register_config_handler(CONF_INSTANCE,
                                parse_config,
                                free_config,
                                "Instance definition");

}

